import "css/common.css"

import Vue from "vue"
import axios from "axios"
import url from "js/api.js"
import jquery from "js/jquery.js"
import {
  Swipe,
  SwipeItem
} from 'mint-ui';


let data = {
  cityId: "500100",
  source: "wap"
}
let app = new Vue({
  el: "#app",
  data: {
    imgList: null,
    speciallist: null,
    columnlist: null,
    adList: null,
    resultlist: null,
    houseList: null,
    houseList1: null,
    houseList2: null,
    cityList: null,
    show: null
  },
  created: function () {
    this.getCity()
    this.getHome()
    this.getHouseList()
  },
  methods: {
    getHome: function () {
      axios.post(url.getHome, $.param(
        data)).then(res => {
        this.imgList = res.data.result.carousel
        this.speciallist = res.data.result.special
        this.columnlist = res.data.result.column
        this.adList = res.data.result.ad
      })
    },
    getHouseList: function () {
      axios.post(url.getRecommend, $.param(
        data)).then(res => {
        this.resultlist = res.data.result
        this.houseList = res.data.result[0].houseList
        this.houseList1 = res.data.result[1].houseList
      })
    },
    getCity: function () {
      axios.post(
        url.getCity, $.param(data)
      ).then(res => {
        app.cityList = res.data.result
      })
    },
    btnSeemore: function (e) {
      if ($(e.target).prev().text() === "日租") {
        document.location.href = "Dailyrent/dailyrentpage.html"
      } else if ($(e.target).prev().text() === "长租") {
        document.location.href = "Longrent/longrentpage.html"
      } else if ($(e.target).prev().text() === "时租") {
        console.log("未开放")
      }
    },
    imgclick: function (imgItem) {
      if (imgItem.imgHref === "" & imgItem.houseMasterId != 0 & imgItem.houseType === 1) {
        var imgvalue = imgItem.houseMasterId;
        location.href = 'Longrent/longhousinglist.html?' + 'houseMasterId=' + imgvalue
      } else if (imgItem.imgHref === "" & imgItem.houseMasterId != 0 & imgItem.houseType === 2) {
        location.href = 'Dailyrent/dailyhousinglist.html?' + 'houseMasterId=' + imgItem.houseMasterId
      } else if (imgItem.imgHref) {
        location.href = imgItem.imgHref
      } else {
        console.log("banner error")
      }
    },
    specialimg: function (specialItem) {
      if (specialItem.houseType === 1) {
        location.href = 'Longrent/longhousinglist.html?' +
          "houseMasterId=" + specialItem.houseMasterId
      } else if (specialItem.houseType === 2) {
        location.href = 'Dailyrent/dailyhousinglist.html?' +
          "houseMasterId=" + specialItem.houseMasterId
      } else if (specialItem.houseType === 3) {}
    },
    test: function (columnItem) {
      if (columnItem.title === "长租") {
        document.location.href = "Longrent/longrentpage.html"
      } else if (columnItem.title === "日租") {
        document.location.href = "Dailyrent/dailyrentpage.html"
      } else if (columnItem.title === "房东招募") {
        document.location.href = "else/join.html"
      } else {}
    },
    btnSeemore: function (e) {
      if ($(e.target).prev().text() === "日租") {
        document.location.href = "Dailyrent/dailyhousinglist.html"
      } else if ($(e.target).prev().text() === "长租") {
        document.location.href = "Longrent/longhousinglist.html"
      } else if ($(e.target).prev().text() === "时租") {

      }
    },
    getHouse: function (houseItem) {
      location.href = 'Dailyrent/dailyparticulars.html?' + 'houseId=' + encodeURI(houseItem.houseId) +
        '&lng=' + encodeURI(houseItem.lng) + '&lat=' + encodeURI(houseItem.lat);
    },
    getHouse1: function (houseItem1) {
      location.href = 'Longrent/longparticulars.html?' + 'houseId=' + encodeURI(houseItem1.houseId) +
        '&lng=' + encodeURI(houseItem1.lng) + '&lat=' + encodeURI(houseItem1.lat)
    },
    citySelect: function () {
      app.show = true
    },
    selectCity: function (city) {
      app.show = false
      data.cityId = city.cityid
      app.getImg2()
    },
    cityBack: function () {
      app.show = false
    },

  },
  components: {
    Swipe,
    SwipeItem
  }
})
